package org.finesys.common.file.client.oss.minio;


import org.finesys.common.file.client.FileTemplate;
import org.finesys.common.file.client.oss.http.MinioEndPoint;
import org.finesys.common.file.properties.FileProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.AllArgsConstructor;

/**
 * 云服务存储处理
 * minio云服务存储
 */
@AllArgsConstructor
@Configuration
public class MinioAutoConfiguration {

    private final FileProperties fileProperties;


    @Bean
    @ConditionalOnMissingBean(MinioEndPoint.class)
    @ConditionalOnProperty(value = "file.minio.info", havingValue = "true")
    public MinioEndPoint minioEndPoint(MinioTemplate minioTemplate) {
        return new MinioEndPoint(minioTemplate);
    }

    @Bean
    @ConditionalOnMissingBean(MinioTemplate.class)
    @ConditionalOnProperty(value = "file.minio.enable", havingValue = "true")
    public FileTemplate minioTemplate() {
        return new MinioTemplate(fileProperties);
    }

}
